<template>
	<div class="table">
		<div class="crumbs">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item><i class="el-icon-tickets"></i>商家管理</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="container">
			<div class="handle-box flex justify-between">
				<div>
					<span>审核状态：</span>
					<el-select v-model="search_status" placeholder="请选择" @change="statusChange">
						<el-option v-for="item in statusOptions" :key="item.id" :label="item.name" :value="item.id">
						</el-option>
					</el-select>
					<span class="margin-left-sm">关键字：</span>
					<el-input v-model="search_keyName" style="width: 250px;" placeholder="请输入关键字"></el-input>
					<el-button type="primary" class="margin-left-sm" @click="search">搜索</el-button>
				</div>
				<el-button type="success" @click="addBusiness">新增</el-button>
			</div>
			<el-table :data="tableData" border style="width: 100%" ref="tableData">
				<el-table-column prop="name" label="商家名称" sortable width="150">
				</el-table-column>
				<el-table-column prop="storeCode" label="信用编号">
				</el-table-column>
				<el-table-column prop="inDate" label="入驻时间">
				</el-table-column>
				<el-table-column prop="applyTime" label="申请时间">
				</el-table-column>
				<el-table-column prop="checkTime" label="审核通过时间">
				</el-table-column>
				<el-table-column prop="createrName" label="创建人">
				</el-table-column>
				<el-table-column prop="createrPhone" label="创建人手机号">e
				</el-table-column>

				<el-table-column label="操作" width="320">
					<template slot-scope="scope">
						<el-button size="small" @click="examine(scope.row)" type="success" v-if="search_status === 0 ">审核</el-button>
						<el-button size="small" @click="employ(scope.row)" type="info">招聘</el-button>
						<el-button size="small" @click="manager(scope.row)" type="primary">管理员</el-button>
						<el-button size="small" @click="editStore(scope.row)" type="warning">修改</el-button>
						<el-button size="small" @click="deleteStore(scope.row)" type="danger">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination" v-if="tableData.length != 0">
				<el-pagination @current-change="getTableList" :page-size="size" :current-page.sync="pageNum" layout="total, prev, pager, next,jumper,slot"
				 :page-count="pages" :total="total">
					<span class="goPize">前往</span>
				</el-pagination>
			</div>
		</div>

		<!-- 审核弹窗 -->
		<el-dialog title="商家审核" :visible.sync="examineDialogFormVisible">
			<div style="width: 80%;margin: 0 auto;">
				<div>
					<el-row class="text-lg margin-tb-xs">
						<el-col :span="4">
							商家名称：
						</el-col>
						<el-col :span="17" :offset="1">
							{{exanineDetail.name}}
						</el-col>
					</el-row>
					<el-row class="text-lg margin-tb-xs">
						<el-col :span="4">
							商户手机号：
						</el-col>
						<el-col :span="17" :offset="1">
							{{exanineDetail.phone}}
						</el-col>
					</el-row>
					<el-row class="text-lg margin-tb-xs">
						<el-col :span="4">
							商户身份证：
						</el-col>
						<el-col :span="17" :offset="1">
							{{exanineDetail.cardNo}}
						</el-col>
					</el-row>
					<el-row class="text-lg margin-tb-xs">
						<el-col :span="4">
							信用代码：
						</el-col>
						<el-col :span="17" :offset="1">
							{{exanineDetail.storeCode}}
						</el-col>
					</el-row>
					<el-row class="text-lg margin-tb-xs">
						<el-col :span="4">
							商家介绍：
						</el-col>
						<el-col :span="17" :offset="1">
							{{exanineDetail.basicSituation}}
						</el-col>
					</el-row>
					<el-row class="text-lg margin-tb-xs">
						<el-col :span="4">
							营业执照：
						</el-col>
						<el-col :span="17" :offset="1">
							<img width="120px" :src="exanineDetail.storeImg">
						</el-col>
					</el-row>
				</div>
				<el-form :model="examineForm" label-width="100px" ref="examineForm" :rules="examineRules">
					<el-form-item label="审核" prop="checkStatus">
						<el-select v-model="examineForm.checkStatus" placeholder="请选择审核状态">
							<el-option label="同意" value="1"></el-option>
							<el-option label="拒绝" value="2"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="拒绝理由" v-if="examineForm.checkStatus === '2'" prop="reason">
						<el-input type="textarea" style="width:300px" v-model="examineForm.reason"></el-input>
					</el-form-item>
				</el-form>
				<div slot="footer" class="dialog-footer">
					<el-button @click="examineDialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="saveExamine('examineForm')">确定</el-button>
				</div>
			</div>
		</el-dialog>

		<el-dialog title="删除商家" :visible.sync="deleteDialogVisible" width="30%">
			<span>理由：</span>
			<el-input type="textarea" style="width:300px" v-model="reason"></el-input>
			<span slot="footer" class="dialog-footer">
				<el-button @click="deleteDialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="saveDelete">确 定</el-button>
			</span>
		</el-dialog>

		<!-- 招聘弹窗 -->
		<el-dialog title="招聘" :visible.sync="dialogEmploy" width="75%">
			<div class="container">
				<div class="handle-box flex justify-between">
					<div>
						<!-- <span>审核状态：</span>
						<el-select v-model="search_Employmark" placeholder="请选择" @change="statusChange">
							<el-option v-for="item in statusEmployOptions" :key="item.id" :label="item.name" :value="item.id">
							</el-option>
						</el-select> -->
						<span class="margin-left-sm">关键字：</span>
						<el-input v-model="search_keyEmployName" style="width: 250px;" placeholder="请输入关键字"></el-input>
						<el-button type="primary" class="margin-left-sm" @click="searchEmploy">搜索</el-button>
					</div>
					<el-button type="success" @click="addEmploy">新增</el-button>
				</div>
				<el-table :data="tableEmployData" border style="width: 100%" ref="tableData">
					<el-table-column prop="title" label="标题" sortable width="150">
					</el-table-column>
					<el-table-column prop="salary" label="具体的薪资范围">
					</el-table-column>
					<el-table-column prop="phone" label="联系电话">
					</el-table-column>
					<el-table-column prop="startDate" label="生效日期">
					</el-table-column>
					<el-table-column prop="endDate" label="截止日期">
					</el-table-column>
					<el-table-column prop="address" label="地址">
					</el-table-column>
					<el-table-column label="操作" width="280">
						<template slot-scope="scope">
							<el-button size="small" @click="goDeliver(scope.row)" type="info">简历</el-button>
							<el-button size="small" @click="editEmployStore(scope.row)" type="primary">修改</el-button>
							<el-button size="small" @click="deleteEmployStore(scope.row)" type="danger">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
				<div class="pagination" v-if="tableData.length != 0">
					<el-pagination @current-change="getTableEmployList" :page-size="sizeEmploy" :current-page.sync="pageNumEmploy"
					 layout="total, prev, pager, next,jumper,slot" :page-count="pagesEmploy" :total="totalEmploy">
						<span class="goPize">前往</span>
					</el-pagination>
				</div>
			</div>
		</el-dialog>

		<!-- 管理员弹窗 -->
		<el-dialog title="管理员" :visible.sync="dialogManager" width="50%">
			<div class="container">
				<div class="handle-box flex justify-between">
					<!-- <el-button type="success" @click="addManager">新增</el-button> -->
					<el-button type="success" @click="innerVisible =true">新增</el-button>
				</div>
				<el-table :data="tableManagerData" border style="width: 100%" ref="tableData">
					<el-table-column prop="name" label="姓名" sortable width="150">
					</el-table-column>
					<el-table-column prop="phone" label="手机号">
					</el-table-column>
					<!-- <el-table-column prop="" label="联系电话">
					</el-table-column>		 -->			
					<el-table-column label="操作" width="280">
						<template slot-scope="scope">							
							<el-button size="small" @click="deleteManager(scope.row)" type="danger">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
				<!-- <div class="pagination" v-if="tableManagerData.length != 0">
					<el-pagination @current-change="getTableManagerList" :page-size="sizeManager" :current-page.sync="pageNumManager"
					 layout="total, prev, pager, next,jumper,slot" :page-count="pagesManager" :total="totalManager">
						<span class="goPize">前往</span>
					</el-pagination>
				</div> -->
			</div>
			<el-dialog width="30%" title="新增管理员" :visible.sync="innerVisible" append-to-body>
				<!-- :rules="managerRules" -->
				<el-form :model="ruleManagerForm" status-icon  ref="ruleManagerForm" label-width="100px" class="demo-ruleForm">
					<el-form-item label="手机号" prop="phone">
						<el-input v-model="ruleManagerForm.phone" autocomplete="off"></el-input>
					</el-form-item>
					<el-form-item label="管理员类型" prop="type">
						<el-radio-group v-model="ruleManagerForm.type">
							<el-radio :label="1">创建人</el-radio>
							<el-radio :label="2">管理员</el-radio>
						</el-radio-group>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="submitForm('ruleManagerForm')">保存</el-button>
					</el-form-item>
				</el-form>
			</el-dialog>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name: 'business',
		data() {
			return {
				ruleManagerForm: {
					phone:'',
					type:0
				},
				innerVisible: false,
				dialogManager: false,
				managerId: '',
				sizeManager: 10,
				pageNumManager: 1,
				pagesManager: null,
				totalManager: 0,
				tableManagerData: [],
				storeEmployId: '',
				sizeEmploy: 10,
				pageNumEmploy: 1,
				pagesEmploy: null,
				totalEmploy: 0,
				tableEmployData: [],
				search_keyEmployName: '',
				search_Employmark: 1,
				statusEmployOptions: [{
					id: 0,
					name: '审批中'
				}, {
					id: 1,
					name: '进行中'
				}, {
					id: 2,
					name: '拒绝'
				}, {
					id: 4,
					name: '过期'
				}],

				businessDetail: {},
				dialogEmploy: false, //招聘弹窗
				deleteId: '',
				reason: '',
				deleteDialogVisible: false,
				exanineDetail: {},
				examineForm: {
					checkStatus: '1',
					reason: '',
				},
				examineRules: {
					reason: [{
						required: true,
						message: '请输入拒绝理由',
						trigger: 'blur'
					}],
					checkStatus: [{
						required: true,
						message: '请选择审核意见',
						trigger: 'change'
					}],
				},
				examineDialogFormVisible: false,
				exanineId: '', //审核id
				size: 10,
				pageNum: 1,
				pages: null,
				total: 0,
				tableData: [], //表数据
				search_status: 1, //审核状态
				search_keyName: '',
				statusOptions: [{
					id: 0,
					name: '未审核'
				}, {
					id: 1,
					name: '审核通过'
				}, {
					id: 2,
					name: '未通过'
				}, {
					id: 4,
					name: '禁用'
				}],
			}
		},
		watch: {

		},
		mounted() {
			this.getTableList();
		},
		methods: {
			//删除管理员
			deleteManager(row){
				let that = this;
				that.HttpUtil.delete(
					that,
					that.Global.URLPATH.DELETEMANAGER, {
						id:row.id,
						storeId:that.managerId,
						type:row.type,
					},
					function(res) {						
						if (res.status == 0) {
							that.$message.success('删除成功！');							
							that.getTableManagerList();
						}
					},
					function(err) {
				
					});
			},
			//新增管理员
			submitForm(formName){				
				let that = this;
				that.HttpUtil.post(
					that,
					that.Global.URLPATH.ADDMANAGER, {
						phone:that.ruleManagerForm.phone,
						storeId:that.managerId,
						type:that.ruleManagerForm.type,
					},
					function(res) {						
						if (res.status == 0) {
							that.$message.success('新增成功');
							that.innerVisible = false;
							that.getTableManagerList();
						}
					},
					function(err) {
				
					});
			},
			//去简历
			goDeliver(row) {
				this.$router.push({
					name: 'deliver',
					params: {
						id: row.id
					}
				})
				this.dialogEmploy = false;
			},
			//编辑招聘
			editEmployStore(row) {
				this.$router.push({
					name: 'editEmploy',
					params: {
						id: row.id
					}
				})
				this.dialogEmploy = false;
			},
			//删除招聘
			deleteEmployStore(row) {
				let that = this;
				that.HttpUtil.delete(
					that,
					that.Global.URLPATH.ADDEMPLOY + row.id, {
						id: row.id
					},
					function(res) {
						if (res.status == 0) {
							that.$message.success('删除成功！')
							that.getTableEmployList();
						}
					},
					function(err) {

					});
			},
			getTableEmployList(pageNum) {
				let that = this;
				pageNum = pageNum ? pageNum : that.pageNumEmploy;
				that.HttpUtil.encryptGet(
					that,
					that.Global.URLPATH.GETEMPLOY, {
						storeId: that.storeEmployId,
						mark: that.search_Employmark,
						keyName: that.search_keyEmployName,
						pageNum: pageNum,
						size: 10
					},
					function(res) {
						if (res.data.list.length != 0) {
							that.tableEmployData = res.data.list;
							that.pagesEmploy = res.data.pages;
							that.pageNumEmploy = res.data.pageNum;
							that.totalEmploy = res.data.total;
						} else {
							that.$message.warning("没有记录！");
							that.tableEmployData = [];
							that.pagesEmploy = 1;
							that.totalEmploy = 1;
							that.pageNumEmploy = 1;
						}
					},
					function(data) { //访问失败
						that.tableData = [];
						that.total = 1;
						that.$message.success(data.msg);
					});
			},
			searchEmploy() {
				this.getTableEmployList();
			},
			//新增管理员
			addManager() {

			},
			//获取管理员列表
			getTableManagerList(pageNum) {
				let that = this;
				pageNum = pageNum ? pageNum : that.pageNumEmploy;
				that.HttpUtil.encryptGet(
					that,
					that.Global.URLPATH.GETMANAGER, {
						id: that.managerId,
						pageNum: pageNum,
						size: 10
					},
					function(res) {
						if (res.data.length != 0) {
							that.tableManagerData = res.data;
							// that.pagesManager = res.data.pages;
							// that.pageNumManager = res.data.pageNum;
							// that.totalManager = res.data.total;
						} else {
							that.$message.warning("没有记录！");
							that.tableManagerData = [];
							// that.pagesManager = 1;
							// that.totalManager = 1;
							// that.pageNumManager = 1;
						}
					},
					function(data) { //访问失败
						that.tableData = [];
						that.total = 1;
						that.$message.success(data.msg);
					});
			},
			//获取公司招聘信息
			getBusinessEmploy() {
				let that = this;
				that.HttpUtil.post(
					that,
					that.Global.URLPATH.GETBUSINESSEMPLOY, {
						storeId: this.businessDetail.id,
					},
					function(res) {
						if (res.data.list.length != 0) {

						} else {

						}
					},
					function(data) { //访问失败

					});
			},
			//管理员弹窗
			manager(row) {
				this.dialogManager = true;
				this.managerId = row.id;
				this.getTableManagerList();
			},
			//招聘弹窗
			employ(row) {
				this.storeEmployId = row.id;
				this.businessDetail = row;
				this.dialogEmploy = true;
				this.getTableEmployList();
			},
			//新增招聘
			addEmploy() {
				this.$router.push({
					name: 'addEmploy',
					params: {
						id: this.businessDetail.id,
						name: this.businessDetail.name
					}
				})
				this.dialogEmploy = false;
			},
			//编辑
			editStore(row) {
				this.$router.push({
					name: 'editBusiness',
					params: {
						id: row.id
					}
				})
			},
			//删除保存			
			saveDelete() {
				let that = this;
				if (that.reason) {
					that.HttpUtil.delete(
						that,
						that.Global.URLPATH.DELETEEXAMINE + that.deleteId, {
							id: that.deleteId,
							reason: that.reason
						},
						function(res) {
							if (res.status == 0) {
								that.$message.success("删除成功");
								that.deleteDialogVisible = false;
								that.getTableList();
							}
						},
						function(err) {});
				} else {
					that.$message.warning('请输入理由！')
				}
			},
			//删除
			deleteStore(row) {
				// encryptDelete
				this.deleteId = row.id;
				this.deleteDialogVisible = true

			},
			//审核类型选择
			statusChange() {
				this.getTableList();
			},
			//审核保存
			saveExamine(formName) {
				let that = this;
				that.examineForm.id = that.exanineId;
				that.$refs[formName].validate((valid) => {
					if (valid) {
						that.HttpUtil.post(
							that,
							that.Global.URLPATH.EXAMINE, that.examineForm,
							function(res) {
								that.$message.success("审核成功");
								that.examineDialogFormVisible = false
								that.getTableList();
							},
							function(err) {});

					} else {
						console.log('error submit!!');
						return false;
					}
				});

			},
			//审核
			examine(row) {
				this.exanineDetail = row;
				this.exanineId = row.id;
				this.examineDialogFormVisible = true;
			},
			//新增
			addBusiness() {
				this.$router.push({
					name: 'addBusiness'
				});
			},
			//搜索
			search() {
				this.getTableList(1);
			},
			//获取表数据		
			getTableList(pageNum) {
				let that = this;
				pageNum = pageNum ? pageNum : that.pageNum;
				that.HttpUtil.get(
					that,
					that.Global.URLPATH.GETBUSINESS, {
						checkStatus: that.search_status,
						keyName: that.search_keyName,
						pageNum: pageNum,
						size: 10
					},
					function(res) {
						if (res.data.list.length != 0) {
							that.tableData = res.data.list;
							that.pages = res.data.pages;
							that.pageNum = res.data.pageNum;
							that.total = res.data.total;
						} else {
							that.$message.warning("没有记录！");
							that.tableData = [];
							that.pages = 1;
							that.total = 1;
							that.pageNum = 1;
						}
					},
					function(data) { //访问失败
						that.tableData = [];
						that.total = 1;
						that.$message.success(data.msg);
					});
			},
		}
	}
</script>

<style>
	@import "../../../assets/css/common.css";
</style>
